package com.newa.actions;

import java.util.ArrayList;

import org.apache.log4j.Logger;
import org.hibernate.Session;

import com.newa.beans.Work;
import com.newa.dao.DAOWorks;
import com.newa.listeners.Listener;
import com.newa.utils.HibUtil;
import com.opensymphony.xwork2.ActionSupport;

public class getAllWorksForSection extends ActionSupport {
	private Logger LOG = Logger.getLogger(getAllWorksForSection.class);
	private int id;
	private ArrayList<Work> works;

	@Override
	public String execute() throws Exception {
		Session session = HibUtil.getSessionFactory().openSession();
		DAOWorks daow = new DAOWorks(session);
		try {

			ArrayList<Work> ress = daow.getAllWorksBySectionId(id);
			setRes(ress);
		} catch (Exception e) {
			LOG.warn(e);
			throw new RuntimeException(e);
		} finally {
			daow.closeSession().close();
		}
		return "success";
	}

	public ArrayList<Work> getWorks() {
		return works;
	}

	public void setRes(ArrayList<Work> works) {
		this.works = works;
	}

	public int getId() {
		return id;
	}

	public void setId(int id) {
		this.id = id;
	}
}
